<?php
/**
 * 设置nd属性
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/2/8
 * Time: 9:56
 */
define('IN_IA', true);
define('STARTTIME', microtime());
define('IA_ROOT', $_SERVER['DOCUMENT_ROOT']);
define('MAGIC_QUOTES_GPC', (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) || @ini_get('magic_quotes_sybase'));
define('TIMESTAMP', time());
$_W = $_GPC = array();

require IA_ROOT . '/framework/version.inc.php';
require IA_ROOT . '/framework/const.inc.php';
require IA_ROOT . '/framework/class/loader.class.php';
$configfile = IA_ROOT . "/data/config.php";
require  $configfile;
load()->func('global');
load()->func('pdo');
load()->func('compat');
load()->classs('account');
load()->classs('agent');
load()->model('cache');
load()->model('account');
load()->model('setting');

define('CLIENT_IP', getip());

$_W['config'] = $config;
$_W['config']['db']['tablepre'] = !empty($_W['config']['db']['master']['tablepre']) ? $_W['config']['db']['master']['tablepre'] : $_W['config']['db']['tablepre'];
$_W['timestamp'] = TIMESTAMP;
$_W['charset'] = $_W['config']['setting']['charset'];
$_W['clientip'] = CLIENT_IP;

unset($configfile, $config);

define('ATTACHMENT_ROOT', IA_ROOT .'/attachment/');

define('DEVELOPMENT', $_W['config']['setting']['development'] == 1);
if(DEVELOPMENT) {
    ini_set('display_errors', '1');
    error_reporting(E_ALL ^ E_NOTICE);
} else {
    error_reporting(0);
}
if(!in_array($_W['config']['setting']['cache'], array('mysql', 'file', 'memcache'))) {
    $_W['config']['setting']['cache'] = 'mysql';
}
load()->func('cache');

if(function_exists('date_default_timezone_set')) {
    date_default_timezone_set($_W['config']['setting']['timezone']);
}
if(!empty($_W['config']['setting']['memory_limit']) && function_exists('ini_get') && function_exists('ini_set')) {
    if(@ini_get('memory_limit') != $_W['config']['setting']['memory_limit']) {
        @ini_set('memory_limit', $_W['config']['setting']['memory_limit']);
    }
}
$_W['ishttps'] = !empty($_W['config']['setting']['https']) ? true : (strtolower(($_SERVER['SERVER_PORT'] == 443 || (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') ? true : false)));
$_W['isajax'] = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
$_W['ispost'] = $_SERVER['REQUEST_METHOD'] == 'POST';

$_W['sitescheme'] = $_W['ishttps'] ? 'https://' : 'http://';
$_W['script_name'] = htmlspecialchars(scriptname());
$sitepath = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
$_W['siteroot'] = htmlspecialchars($_W['sitescheme'] . $_SERVER['HTTP_HOST'] . $sitepath);

if(substr($_W['siteroot'], -1) != '/') {
    $_W['siteroot'] .= '/';
}
$urls = parse_url($_W['siteroot']);
$urls['path'] = str_replace(array('/web', '/app', '/payment/wechat', '/payment/alipay', '/api'), '', $urls['path']);
$_W['siteroot'] = $urls['scheme'].'://'.$urls['host'].((!empty($urls['port']) && $urls['port']!='80') ? ':'.$urls['port'] : '').$urls['path'];
$_W['siteurl'] = $urls['scheme'].'://'.$urls['host'].((!empty($urls['port']) && $urls['port']!='80') ? ':'.$urls['port'] : '') . $_W['script_name'] . (empty($_SERVER['QUERY_STRING'])?'':'?') . $_SERVER['QUERY_STRING'];

if(MAGIC_QUOTES_GPC) {
    $_GET = istripslashes($_GET);
    $_POST = istripslashes($_POST);
    $_COOKIE = istripslashes($_COOKIE);
}
$cplen = strlen($_W['config']['cookie']['pre']);
foreach($_COOKIE as $key => $value) {
    if(substr($key, 0, $cplen) == $_W['config']['cookie']['pre']) {
        $_GPC[substr($key, $cplen)] = $value;
    }
}
unset($cplen, $key, $value);

$_GPC = array_merge($_GET, $_POST, $_GPC);
$_GPC = ihtmlspecialchars($_GPC);
if(!$_W['isajax']) {
    $input = file_get_contents("php://input");
    if (!empty($input)) {
        $__input = @json_decode($input, true);
        if (!empty($__input)) {
            $_GPC['__input'] = $__input;
            $_W['isajax'] = true;
        }
    }
    unset($input, $__input);
}

setting_load();
if (empty($_W['setting']['upload'])) {
    $_W['setting']['upload'] = array_merge($_W['config']['upload']);
}
$_W['attachurl'] = $_W['attachurl_local'] = $_W['siteroot'] . $_W['config']['upload']['attachdir'] . '/';
if (!empty($_W['setting']['remote']['type'])) {
    if ($_W['setting']['remote']['type'] == 1) {
        $_W['attachurl'] = $_W['attachurl_remote'] = $_W['setting']['remote']['ftp']['url'] . '/';
    } elseif ($_W['setting']['remote']['type'] == 2) {
        $_W['attachurl'] = $_W['attachurl_remote'] = $_W['setting']['remote']['alioss']['url'].'/';
    } elseif ($_W['setting']['remote']['type'] == 3) {
        $_W['attachurl'] = $_W['attachurl_remote'] = $_W['setting']['remote']['qiniu']['url'].'/';
    } elseif ($_W['setting']['remote']['type'] == 4) {
        $_W['attachurl'] = $_W['attachurl_remote'] = $_W['setting']['remote']['cos']['url'].'/';
    }
}
$_W['os'] = Agent::deviceType();
if($_W['os'] == Agent::DEVICE_MOBILE) {
    $_W['os'] = 'mobile';
} elseif($_W['os'] == Agent::DEVICE_DESKTOP) {
    $_W['os'] = 'windows';
} else {
    $_W['os'] = 'unknown';
}

$_W['container'] = Agent::browserType();
if(Agent::isMicroMessage() == Agent::MICRO_MESSAGE_YES) {
    $_W['container'] = 'wechat';
} elseif ($_W['container'] == Agent::BROWSER_TYPE_ANDROID) {
    $_W['container'] = 'android';
} elseif ($_W['container'] == Agent::BROWSER_TYPE_IPAD) {
    $_W['container'] = 'ipad';
} elseif ($_W['container'] == Agent::BROWSER_TYPE_IPHONE) {
    $_W['container'] = 'iphone';
} elseif ($_W['container'] == Agent::BROWSER_TYPE_IPOD) {
    $_W['container'] = 'ipod';
} else {
    $_W['container'] = 'unknown';
}

$controller = $_GPC['c'];
$action = $_GPC['a'];
$do = $_GPC['do'];

header('Content-Type: text/html; charset=' . $_W['charset']);

$act = !empty($_GET['act'])?$_GET['act'] : 'index';
if($act == 'set') {
    pdo_query("update ims_meepo_xianchang_user set nd_id=11,status=1 where realname='刘少军' ");
    pdo_query("update ims_meepo_xianchang_user set nd_id=11,status=1 where realname='林汉权' ");
    pdo_query("update ims_meepo_xianchang_user set nd_id=11,status=1 where realname='张丽娟' ");
    pdo_query("update ims_meepo_xianchang_user set nd_id=10,status=1 where realname='杨美娟' ");
    pdo_query("update ims_meepo_xianchang_user set nd_id=10,status=1 where realname='许金森' ");
    pdo_query("update ims_meepo_xianchang_user set nd_id=9,status=1 where realname='吴学溦' ");
    pdo_query("update ims_meepo_xianchang_user set nd_id=9,status=1 where realname='陈芳' ");
    pdo_query("update ims_meepo_xianchang_user set nd_id=9,status=1 where realname='陈应全' ");
    pdo_query("update ims_meepo_xianchang_user set nd_id=12,status=1 where realname='曾志军' ");
    pdo_query("update ims_meepo_xianchang_user set nd_id=12,status=1 where realname='薛一航' ");
    header("Location:/attachment/images/1/2018/01/setnd.php?act=list");
} else if($act == 'reset') {
    pdo_query("update ims_meepo_xianchang_user set nd_id=0");
    header("Location:/attachment/images/1/2018/01/setnd.php?act=list");
} else if($act == 'index' || $act == '') {
    echo '<p style="font-size: 20px;"><a href="/attachment/images/1/2018/01/setnd.php?act=set">设置</a></p>';
    echo '<p style="font-size: 20px;"><a href="/attachment/images/1/2018/01/setnd.php?act=reset">取消设置</a></p>';
    echo '<p style="font-size: 20px;" ><a href="/attachment/images/1/2018/01/setnd.php?act=list">查看</a></p>';
} else if($act=="list"){
    $result = pdo_fetchall("select * from ims_meepo_xianchang_user where nd_id != 0");
    for($i = 0;$i < count($result);$i++) {
        echo "<p>".($i + 1)."、".$result[$i]["realname"].",:".$result[$i]["nd_id"]."</p>";
    }
    echo '<p style="font-size: 20px;"><a href="/attachment/images/1/2018/01/setnd.php?act=index">返回</a></p>';
}
